LLVM_CONFIG=llvm-config-12
CXX=clang++-12

LDFLAGS+=$(shell $(LLVM_CONFIG) --ldflags)
# COMMON_FLAGS=-Wall -Wextra
COMMON_FLAGS=
CXXFLAGS+=$(COMMON_FLAGS) $(shell $(LLVM_CONFIG) --cxxflags) -fno-rtti
CPPFLAGS+=$(shell $(LLVM_CONFIG) --cppflags) -g -I$(SRC_DIR)
CLANGLIBS= \
  -Wl,--start-group \
  -lclang \
  -lclangFrontend \
  -lclangDriver \
  -lclangSerialization \
  -lclangParse \
  -lclangSema \
  -lclangAnalysis \
  -lclangEdit \
  -lclangAST \
  -lclangLex \
  -lclangBasic \
  -lclangTooling \
  -lclangCodeGen \
  -Wl,--end-group

LLVMLIBS=$(shell $(LLVM_CONFIG) --libs)
SYSTEMLIBS=$(shell $(LLVM_CONFIG) --system-libs)

SRC=$(wildcard *.cpp)
OBJ=$(patsubst %.cpp, %, $(SRC))

.PHONY:all clean
all: $(OBJ)
# ctest: find_class_decls ast_traversal diagnostics_example
# cpptest: front_end

%:%.cpp
	@echo Compiling $*.cpp
	$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) -o $@ $(LDFLAGS) $(CLANGLIBS) $(LLVMLIBS) $(SYSTEMLIBS) `$(LLVM_CONFIG) --libs bitreader core support`

clean:
	rm -rf $(OBJ)
